
from django.utils.deprecation import MiddlewareMixin
from django.http import HttpResponse

class LaufingMiddleware(MiddlewareMixin):

    def process_request(self, request):

        # 接收的还是WSGIRequest对象
        print(request.method, request.path_info)

        print(request.headers)
        print(request.POST)
        print("中间件正在处理请求。。。在进入路由之前")

        return None   # 继续走到路由

#         return response

    def process_view(self, request, callback, cb_args, cb_kwargs):

        print("中间件正在处理请求， 在视图函数之前。。。")

        return None   # 继续走到 视图函数

    def process_exception(self, request, exception):

        print("中间件处理异常，在视图发生异常时")
        print(exception.args)
        print(exception)
        return  HttpResponse("视图发生异常")

    def process_response(self, request, response):

        print("中间件 处理响应。。。。")
        print("当前响应：", response.content[:100])

        return response
